<template>
<Row class="layout-content-body">

  <dtable :columnsList="columns" v-model="dataAll" :totals="total" 
  :busyName="busyName" :busyTable="busyTable"
  flowstart editCheck @refresh="getall()"
   @add="add" @del="del" @edit="edit" @delList="delList" 
  :loading="loading"></dtable>
</Row>
</template>

<script>
import {
  timeFormat, currency
} from '@/common/filter'
import dtable from '@/components/table/etable.vue' //采用biztable
export default {
  data() {
    return {
      loading: false, //数据刷新遮罩层
      busyName:"采购订单",
      busyTable:"yjk_buy",
      columns: [
        //多选框
        {
          title: '名称',
          key: 'Name',
          sortable: true
        },
        {
          title: '供应商',
          key: 'PartName',
          sortable: true
        },
        {
          title: '金额',
          key: 'Price',
          sortable: true,
          render: (h, params) => {
            return h('div', [
              h('strong', currency(params.row.Price,"￥"))
            ]);
          }
        },
        {
          title: '说明',
          key: 'Remark',
          sortable: true,
        },
        {
          title: '责任人',
          key: 'Creater',
          sortable: true
        },
        {
          title: '创建时间',
          key: 'Ctime',
          sortable: true,
          render: (h, params) => {
            return h('div', [
              h('strong', timeFormat(params.row.Ctime))
            ]);
          }
        },
      ], //表格样式
      dataAll: [], //表格数据来源
      templist: [],
      dataShow: true, //是否显示表格数据查看表单
      showTemp: false,
      total: 0,
      orderData: {
        edit: false,
        temp: ''
      },
    }
  },
  components: {
    dtable,
  },
  computed: {

  },
  watch: {},
  methods: {
    getall() {
      this.loading = true
      this.$api.getMyBuy().then(res => {
        if (!res.error) {
          // console.log(res.Data)
          this.dataAll = res.Data
          if (this.dataAll) {
            this.total = (this.dataAll).length
          }
        } else {
          this.$Message.error(res.message)
        }
      })
      // this.$api.getTemp().then(res => {
      //   if (!res.error) {
      //     this.templist = res.Data
      //   } else {
      //     this.$Message.error(res.message)
      //   }
      // })
      this.loading = false;
    },
    edit(index) {
      console.log(index.Id)
      this.orderData.order = index
      this.orderData.edit = true
      this.$router.push({
        name: '采购订单明细',
        params: {
          orderData: this.orderData
        }
      })
    },
    add() {
      this.orderData.edit = false
      this.$router.push({
        name: '采购订单明细',
        params: {
          orderData: this.orderData
        }
      })
    },
    del(row) {
      this.$api.deleteOrder(row).then(res => {
        if (!res.error) {
          this.getall()
          this.$Message.success(res.message)
        } else {
          this.$Message.error(res.message, 4)
        }
      })
    },
    delList(row) {
      this.$api.deleteOrderList(row).then(res => {
        if (!res.error) {
          this.getall()
          this.$Message.success(res.message)
        } else {
          this.$Message.error(res.message, 4)
        }
      })
    },
    
  },
  mounted() {
    this.getall()
  }
}
</script>
